{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "BasicNeuralNetCode.ipynb",
      "provenance": [],
      "collapsed_sections": [],
      "authorship_tag": "ABX9TyMm9IIqkxGfLCNAVLW3Tqb6",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/Divyanshu-ISM/Oil-and-Gas-data-analysis/blob/master/BasicNeuralNetCode.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "BbmlySdkVXZj",
        "colab_type": "text"
      },
      "source": [
        "# *CASE1*- 3 Inputs --> 1 Neuron"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "kBuILwxDIfYS",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        ""
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "2sFZM_X-I9tD",
        "colab_type": "text"
      },
      "source": [
        "# My First Neuron Code (inspired by SentDex)\n",
        "Now in this 'SIMPLEST' model, I am assuming that the model has 3 (L-1 or input or previous Neurons) inputting their values into the final (one) neuron. 3--->1"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "SdfnThBxJFjN",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "inputs = [1,2,3]\n",
        "weights = [0.2,0.8,-0.5]\n",
        "bias = 2"
      ],
      "execution_count": 1,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "eUPegNmCJzmm",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "output = inputs[0]*weights[0] + inputs[1]*weights[1] + inputs[2]*weights[2] + bias"
      ],
      "execution_count": 2,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "VTSMqQ5yKJRc",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "2671cf3f-0990-480d-81af-8946b11a0696"
      },
      "source": [
        "print(output) #this is the output of our simple neural network"
      ],
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "2.3\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "U0ARUMPKKWGK",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        ""
      ],
      "execution_count": 3,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "5aVPoRvYS_Yb",
        "colab_type": "text"
      },
      "source": [
        "Every input (arm) --> has a weight 'w' --> multiple w's possible per neuron\n",
        "\n",
        "Every neuron (circle) ---> has a bias ---> only one bias per neuron"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "RCWPjcVyVvug",
        "colab_type": "text"
      },
      "source": [
        "# Case2 -- 4 inputs --> 3 neurons\n",
        "#- Method 1 : Pure Layman way!\n",
        "1. 3 output neurons - 3 unique weight sets with 4 ie, [w1,w2,w3,w4] in each\n",
        "2. 3 output neurons - 3 biasses b1,b2,b3\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jUqa9MwRTBJF",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "i = [1,2,3,2.5]"
      ],
      "execution_count": 4,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "YpcE2xOGdF6E",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "w1 = [0.2,0.8,-0.5,1.0]\n",
        "w2 = [0.5,-0.91,0.26,-0.5]\n",
        "w3 = [-0.26,-0.27,0.17,0.87]"
      ],
      "execution_count": 5,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "99IMxPo4dThY",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "b1 = 2\n",
        "b2 = 3\n",
        "b3 = 0.5"
      ],
      "execution_count": 6,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "HErW8c4ldYXm",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "o1 = i[0]*w1[0] + i[1]*w1[1] + i[2]*w1[2] + i[3]*w1[3] + b1\n",
        "o2 = i[0]*w2[0] + i[1]*w2[1] + i[2]*w2[2] + i[3]*w2[3] + b2\n",
        "o3 = i[0]*w3[0] + i[1]*w3[1] + i[2]*w3[2] + i[3]*w3[3] + b3"
      ],
      "execution_count": 7,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qlq6h7Dtd5A4",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "o = [o1,o2,o3]"
      ],
      "execution_count": 8,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "K2EUiNHjd9nU",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "8007060d-6fed-4e06-c32d-c44cff5b0330"
      },
      "source": [
        "o #correct"
      ],
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[4.8, 1.21, 2.385]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 9
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ZNVAZZwUd-Zg",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "54d0a0df-8bfa-40eb-cbbc-ab75e10beada"
      },
      "source": [
        "#trying out what zip does\n",
        "l1 = [1,2,3]\n",
        "l2 = [10,20,30]\n",
        "l = list(zip(l1,l2))\n",
        "print(l)"
      ],
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[(1, 10), (2, 20), (3, 30)]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "XP2H-jeKf1ju",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "33139904-e775-42ef-978e-c9e347994539"
      },
      "source": [
        "l3 = [[1,2,3],[4,5,6]]\n",
        "l4 = [1,2]\n",
        "print(list(zip(l3,l4)))"
      ],
      "execution_count": 11,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[([1, 2, 3], 1), ([4, 5, 6], 2)]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "SsOe0cCRl4K9",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        ""
      ],
      "execution_count": 11,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1HL45fxUl5iw",
        "colab_type": "text"
      },
      "source": [
        "# Method 2 - Doing it with (for) Loops"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "EBjppIYOgvR0",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "i = [1,2,3,2.5]\n",
        "weights = [w1,w2,w3]\n",
        "biases = [b1,b2,b3]"
      ],
      "execution_count": 12,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "P26hOrkGmbmY",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "layer_outputs = []\n",
        "\n",
        "for weight_set,bias in zip(weights,biases):\n",
        "  z = 0\n",
        "  for n_input,weight in zip(i,weight_set):\n",
        "    z = z + n_input*weight\n",
        "  z = z + bias\n",
        "  layer_outputs.append(z)\n"
      ],
      "execution_count": 13,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "NO8cMb1CncgA",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "b794eae5-b515-4421-8fb2-08d4d3a3ac47"
      },
      "source": [
        "print(layer_outputs)"
      ],
      "execution_count": 14,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[4.8, 1.21, 2.385]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "bdX7dhponkT4",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        ""
      ],
      "execution_count": 14,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1f6s-tryzsh4",
        "colab_type": "text"
      },
      "source": [
        "# Method 3 - Doing it with NumPy and Dot Product"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "0EsqMBTszyyM",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "i = [1,2,3,2.5]\n",
        "weights = [w1,w2,w3]\n",
        "biases = [b1,b2,b3]"
      ],
      "execution_count": 15,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "-CO3kg3J0ImR",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import numpy as np\n",
        "weights = np.array(weights)\n",
        "inputs = np.array(i)\n",
        "biases = np.array(biases)"
      ],
      "execution_count": 27,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "QB_viIFn0ai9",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "858aed9d-a2dc-43ed-a103-5b400c32b9a2"
      },
      "source": [
        "weights.shape, inputs.shape"
      ],
      "execution_count": 22,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "((3, 4), (4,))"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 22
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MAjUBnCo0xtO",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "outputs_without_biases = np.dot(weights,inputs)"
      ],
      "execution_count": 24,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "tZavHd7e1GZO",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "589b2313-5f45-4e73-af90-a240c6eae162"
      },
      "source": [
        "outputs_without_biases.shape, biases.shape"
      ],
      "execution_count": 28,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "((3,), (3,))"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 28
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ZL_lfYsD1OIa",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "output = outputs_without_biases + biases"
      ],
      "execution_count": 31,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "hRxaVAFH1dKE",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "d7bab9b3-d2bf-4ef3-bace-d5921453069c"
      },
      "source": [
        "output #same as before"
      ],
      "execution_count": 33,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([4.8  , 1.21 , 2.385])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 33
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "SqOmj_dV1fGF",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        ""
      ],
      "execution_count": null,
      "outputs": []
    }
  ]
}